package com.guaoran.agricultural.big.data.controller;

import com.guaoran.commons.swagger.ui.entity.Demo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

/**
 * @author : gucheng
 * @Description : <br/>
 *  Swagger首页
 * @date :2018/11/15 14:15
 */
@Api(value = "Swagger首页",tags = "swagger 实例")
@Controller
public class SwaggerController {
    Logger logger = LoggerFactory.getLogger(SwaggerController.class);
    @ApiOperation(value="欢迎界面", notes="进入到swagger界面")
    @GetMapping("/swagger")
    public String swagger(){
        logger.info("进入了..{}","swagger");
        return "redirect:/swagger-ui.html";
    }

    /**
     * 使用注解忽略方法，
     * 如果想忽略整个Controller 的所有方法，将该注解添加的类上就行
     * @return
     */
    @ApiIgnore
    @GetMapping("/demo")
    @ResponseBody
    public String demo(){
        return "success";
    }

    /**
     * 当请求类型是RequestMapping时会生成多个请求实例
     * 即包含：get/post/delete/head/patch/put/options
     */
    //先忽略
    @ApiIgnore
    @RequestMapping("/demo2")
    @ResponseBody
    public String demo2(){
        return "success";
    }

    /**
     * 加上说明
     * @param demo
     * @return
     */
    @ApiOperation(value="这是该接口的描述", notes="这是备注")
    @PostMapping("demo3")
    @ResponseBody
    public String demo3(@ApiParam("这是一个参与方对象") @RequestBody Demo demo){
        return String.valueOf(demo);
    }

    @ApiOperation(value="传参数", notes="这是备注")
    @PostMapping("demo4")
    @ResponseBody
    public String demo4(@ApiParam("这是描述参数的信息") @RequestParam(value = "id" ,defaultValue = "0") String id){
        logger.warn("进入了..demo4,id={}",id);
        return id;
    }

    /**
     * 不使用任何注解也是可以扫描到，
     * 因为在配置文件中配置了扫描的路径
     * @return
     */
    @ResponseBody
    @GetMapping("demo5")
    public String demo5(){
        return "";
    }

    /**
     * 排除路径
     * @return
     */
    @GetMapping("/demo0/demo1")
    @ResponseBody
    public String demo6(){
        return "/demo0/demo1";
    }
    @GetMapping("/demo0/demo2")
    @ResponseBody
    public String demo7(){
        return "/demo0/demo7";
    }


}
